//
// Created by Administrator on 2018/8/29.
//

#include <iostream>
#include "CCSelectSort.h"
/**
 *  选择排序是每次找到最小或者最大的进行
 * */
void CCSelectSort::sort(int *pArry, int len, DIR dir) {
    int tmp, j;
    for( int i = 0; i< len - 1 ; i++ ){
        tmp = 0;
        for( j = 0; j < len - i - 1; j++ ){
            if(dir == UP){
                if( pArry[tmp] > pArry[j]){
                    tmp = j;
                }
            }else{
                if( pArry[tmp] < pArry[j]){
                    tmp = j;
                }
            }
        }
        if( j != i){
            std::cout << "pArray["<< tmp << "]:" << pArry[tmp] << std::endl;
            SWAP(pArry[len -i -1],pArry[tmp]);
        }
        println(pArry,len);
    }
}